class Solution(object):
    def longestLine(self, mat):
        """
        :type mat: List[List[int]]
        :rtype: int
        """
        max_val = 0
        m = len(mat)
        n = len(mat[0])
        for i in range(m):
            count = 0
            for j in range(n):
                if mat[i][j] == 1:
                    count += 1
                    max_val = max(max_val, count)
                else:
                    count = 0
        for j in range(n):
            count = 0
            for i in range(m):
                if mat[i][j] == 1:
                    count += 1
                    max_val = max(max_val, count)
                else:
                    count = 0
        for i in range(m):
            count = 0
            for t in range(min(n, m - i)):
                if mat[i + t][t] == 1:
                    count += 1
                    max_val = max(max_val, count)
                else:
                    count = 0
            count = 0
            for t in range(min(n, m - i)):
                if mat[i + t][n - 1 - t] == 1:
                    count += 1
                    max_val = max(max_val, count)
                else:
                    count = 0
        for j in range(n):
            count = 0
            for t in range(min(m, n - j)):
                if mat[t][j + t] == 1:
                    count += 1
                    max_val = max(max_val, count)
                else:
                    count = 0
            count = 0
            for t in range(min(m, j + 1)):
                if mat[t][j - t] == 1:
                    count += 1
                    max_val = max(max_val, count)
                else:
                    count = 0
        return max_val



data = Solution()
mat = [[0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 1]]
print(data.longestLine(mat))
